# -*- coding:utf-8 -*-
'''
Created on 2011-9-23

@author: wu botao
'''

#默认路径为当前文件夹
def init(logPath='.'):
    from datetime import datetime
    import logging
    import sys
    import os
    
    if not os.path.exists(logPath):
        try:
            os.mkdir(logPath)
        except: 
            logPath = '.'
 
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        filename='%s/%s.log' % (logPath, datetime.now().strftime("%Y-%m-%d")),
                        filemode='a')
    logger = logging.getLogger('logging')
    handler = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(logging.NOTSET)
 
    return logger

